package com.iims.common.utils;

import com.iims.common.constant.Constants;
import com.iims.common.core.domain.BaseEntity;
import com.iims.common.core.domain.HttpParamMap;

import java.util.Iterator;
import java.util.List;

/**
 * 序列号赋值
 *
 * @author fanpei
 * @date 2021/7/13 22:59
 */
public class SeqNumUtils {

    /**
     * 赋值seqNum
     *
     * @param paramMap
     * @param records
     */
    public static List initSeqNum(HttpParamMap paramMap, List records) {
        int pageStart = (int) paramMap.getParams().get(Constants.PAGE_STRAT);
        if (records != null && !records.isEmpty()) {
            //解决All elements are null
            records.remove(null);
            Long seqNum = new Long(pageStart + 1);
            Iterator it = records.iterator();
            while (it.hasNext()) {
                Object obj = it.next();
                BaseEntity baseEntity = (BaseEntity) obj;
                baseEntity.setSeqNum(seqNum);
                seqNum = seqNum + 1;
            }
        }
        return records;

    }
}
